<template>
  <view
    v-show="display"
    class="tui-common-words-container"
    @tap.stop="clickdisplay"
  >
    <view class="tui-common-words-box">
      <view class="tui-common-words-title">
        <view style="title">常用语</view>
        <view class="tui-common-words-close" @tap.stop="handleClose"
          >常用语管理</view
        >
      </view>
      <scroll-view
        class="tui-common-words-list"
        scroll-y="true"
        enable-flex="true"
        style="top: 56px"
      >
        <view
          v-for="(item, index) in commonWordsMatch"
          :key="index"
          class="tui-common-words-item"
          @tap.stop="sendMessage"
          :data-words="item"
        >
          {{ item }}
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
const commonWordsList = [];

export default {
  data() {
    return {
      words: "",
      commonWordsMatch: commonWordsList,
    };
  },
  components: {},
  props: {
    display: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    display: {
      handler: function (newVal) {},
      immediate: true,
    },
  },
  created() {
    this.haderlist();
  },
  methods: {
    clickdisplay() {
      console.log("clickdisplay");
      this.$emit("close", {
        detail: {
          key: "0",
        },
      });
    },
    handleClose() {
      this.$emit("close", {
        detail: {
          key: "0",
        },
      });
      let type = uni.getStorageSync("type");
      if (type) {
        console.log("个人常用语");
        uni.navigateTo({
          url: "/pages/views/packageB/type-jobhunting/jibenshezhi/jibenziliao/changyongyu",
        });
      } else {
        uni.navigateTo({
          url: "/pages/views/packageB/type-recruit/jibenshezhi/renzhen/changyongyu",
        });
      }
    },

    haderlist() {
      this.commonWordsMatch = [];
      let type = uni.getStorageSync("type");
      if (type) {
        this.$http.huirc.hrcphrases().then((res) => {
          if (res.Result) {
            res.Result.forEach((res) => {
              this.commonWordsMatch.push(res.Content);
            });
          }
        });
      } else {
        //公司
        this.$http.huirc.hrcphrasescorp().then((res) => {
          if (res.Result) {
            res.Result.forEach((res) => {
              this.commonWordsMatch.push(res.Content);
            });
          }
        });
      }
    },

    wordsInput(e) {
      (this.commonWordsMatch = []),
        commonWordsList.forEach((item) => {
          if (item.indexOf(e.detail.value) > -1) {
            this.commonWordsMatch.push(item);
          }
        });
      this.setData({
        words: e.detail.value,
        commonWordsMatch: this.commonWordsMatch,
      });
    },

    sendMessage(e) {
      this.$emit("sendMessage", {
        detail: {
          message: e.currentTarget.dataset.words,
        },
      });
    },
  },
};
</script>
<style>
@import "./index.css";
</style>
<style lang="scss" scoped>
.tui-common-words-container {
  border-top-left-radius: 16rpx;
  border-top-right-radius: 16rpx;
}
.tui-common-words-title {
  display: flex;
  justify-content: space-between;
  .title {
    font-weight: 600;
    font-size: 38rpx !important;
  }
  .tui-common-words-close {
    font-size: 30rpx;
    color: #006eff;
    font-family: PingFangSC-Regular;
  }
}
</style>